package bb.lanxing.lib.devices.sprint;

import android.content.Context;
import bb.lanxing.lib.devices.api.ConnectionListener;
import bb.lanxing.lib.devices.api.DeviceManager;
import bb.lanxing.lib.devices.api.SmartDevice;
import bb.lanxing.lib.devices.core.dfu.AbsDfuAdapter;
import bb.lanxing.util.Log;

public class SprintDfuAdapter extends AbsDfuAdapter<XossDevice> implements ConnectionListener {
    public SprintDfuAdapter(Context context, XossDevice xossDevice) {
        super(context, xossDevice);
        xossDevice.registerConnectionListener(this);
    }

    @Override
    public void enterDfuMode() {
        if (isDfuOn()) {
            notifyDufStateChanged();
            return;
        }
        ((XossDevice) this.client).d("Try to enter dfu mode.");
        setDfuModeState(1);
        if (((XossDevice) this.client).sendCmdAsync(Commands.create(-33, null))) {
            ((XossDevice) this.client).d("Send dfu cmd on success.");
            return;
        }
        ((XossDevice) this.client).d("Send dfu cmd on failure.");
        setDfuModeState(4);
    }

    @Override
    public void onConnectionStateChanged(SmartDevice smartDevice, int i, int i2) {
        if (isDfuTurningOn() && i == DeviceManager.STATE_DISCONNECTED) {
            Log.d("Enter dfu mode on success.");
            setDfuModeState(2);
        }
    }
}
